<!DOCTYPE html>
<html lang="en">
<head th:include="certificateWeb/headFoot :: headerCss">
</head>
<link rel="stylesheet" href="/css/certificateWeb/stationApplyFor/infoMain.css">
<body id="body">
<div th:include="certificateWeb/headFoot :: header"></div>
<style>
    .line {
        text-align: center;
        border-bottom: 1px solid #CFCFCF;
        clear: both;
        margin-top: 20px
    }

    .span_1 {
        width: 300px;
        text-align: right;
    }
    .span_2 {
        display: block;
        width: 100%;
        height:30px;
        line-height: 30px;
        text-align: left;

    }
    .span_xz {
        width: 380px;
        height: 200px;
    }

    .cd {
        width: 130px;
        display: inline-block;
        margin: 20px auto auto auto;
    }

    .dong {
        width: 55px;
        display: inline-block;
        margin: 20px auto auto auto;
    }

    .jshi {
        width: 55px;
        display: inline-block;
        margin: 20px auto auto auto;
    }

    .addBtn {
        width: 440px;
        height: 35px;
        background-color: #dddee1;
        border-radius: 3px;
        margin: 20px auto 20px 95px;
        color: #515c34;
        font-weight: bold;
        border: 0px;
    }

    .del {
        width: 55px;
        color: #00b7ee;
        background-color: #dddee1;
        margin-left: 15px;
        display: inline-block;
        border-radius: 3px;
        text-align: center;
        font-size: 16px;
        line-height: 25px;
        margin-top: 34px;
    }
</style>
<main id="main">
    <section class="sec_1">
        <div class="div_1">

        </div>
        <div class="div_2" id="infoBox">
             <span>
                    <input type="hidden" id="infoStoreId" th:value="${infoStoreDO.getId()}"/>
                 <input type="hidden" id="isClose" th:value="${isClose}"/>
             </span>
            <label class="label_title" th:text="${infoStoreDO.getName()}"></label>


            <div id="info">

            </div>


        </div>
        <div style="clear: both"></div>
        <input type="hidden" id="applicationEndTime" th:value="${applicationEndTime}"/>
        <input type="hidden" id="applicationSlogan" th:value="${applicationSlogan}"/>
    </section>
</main>
<div th:include="certificateWeb/headFoot :: footer"></div>
<script src="/js/plugins/layer/layer.min.js" th:src="@{/js/plugins/layer/layer.min.js}"></script>
<script src="/js/plugins/validate/jquery.validate.extend.js"></script>
<script type="text/javascript" src="/js/jquery-form.js"></script>
<script src="/js/jquery.citys.js"></script>
</body>
<script>
    var infoModelList = null;
    var infoStoreId = $("#infoStoreId").val();
    var infoCollect=null;
    var infoCollectId = 0;
    $(function () {

        if($("#isClose").val()==1
        ){
            $("#infoBox").html('<div style="padding:10px 20px;font-size:18px">不在表单填写时间内</div>');
            return false
        }

        //考核站点申请截止标语及截止时间

        ajaxToken("/certificate/findInfoModelList", "Post", {
            infoStoreId : $("#infoStoreId").val()
        }, function (res) {
            var info="";
            var sc="";
            infoModelList = res.infoModelList;
            infoCollect = res.infoCollect;
            if(infoCollect!=null){
                infoCollectId = infoCollect.id;
                var collectContet = eval('('+infoCollect.content+')');
                res.infoModelList.forEach(function (item, index) {
                    //var name=item.name+"";
                    var len = item.name.length;
                    var c="span_1";
                    if(len>25)c="span_2";
                    if (item.type == 0) {
                        info += "<div class='line'>" + item.name + "</div>";
                    } else if (item.type == 1) {
                        info += "            <div class='div_3'>" +
                            "                <label class='"+c+"'>" + item.name + "<span style='color: #D52525'>*</span>：</label>" +
                            "                <div id='adre'>" +
                            "<input type='text' name='" + item.name + "'  id='" + item.name + "' placeholder='请输入" + item.name + "' class='form-control inp_1' value='"+collectContet[item.name]+"'/>" +
                            "                </div>" +
                            "            </div>"
                    } else if (item.type == 2) {
                        info += '                <div class="div_3">' +
                            '                    <label class="'+c+'">' + item.name + '<span style="color: #D52525">*</span>：</label>' +
                            '                    <textarea  id="' + item.name + '" placeholder="' + item.explain + '"  class="form-control inp_2 ' + item.name + '">'+collectContet[item.name]+'</textarea>' +
                            '                </div>';
                    } else if (item.type == 3) {
                        info += '                    <div class="div_3">' +
                            '                        <label class="'+c+'">' + item.name + '<span style="color: #D52525">*</span>：</label>' +
                            '                        <select class="form-control inp_1 ' + item.name + '" id="' + item.name + '">' +
                            '                            <option value="">--请选择--</option>';
                        var selectList = item.content.split(";;");
                        for (var i = 0; i < selectList.length; i++) {
                            if(selectList[i] == collectContet[item.name]){
                                info += '<option value="' + selectList[i] + '" selected>' + selectList[i] + '</option>';
                            }else {
                                info += '<option value="' + selectList[i] + '">' + selectList[i] + '</option>';
                            }
                        }
                        info += '                        </select>' +
                            '                    </div>';
                    } else if (item.type == 4) {
                        info += '<div class="div_3">' +
                            '                	 <label class="'+c+'">' + item.name + '<span style="color: #D52525">*</span>：</label>' +
                            '                		 <button type="button" class="btn inp_1" style="margin-top: 20px" id="' + item.name + 'Upload">' +
                            '                    		 <i class="fa fa-cloud"></i>请上传' + item.name +
                            '               	 	 </button>' +
                            '                	 <input type="text" style="opacity:0;width: 1px;" value="'+collectContet[item.name]+'" class="' + item.name + '" id="' + item.name + '" name="' + item.name + '"/>' +
                            '                	 <span id="' + item.name + 'Test">'+subFileName(collectContet[item.name])+'</span>' +
                            '            	 </div>';
                        sc = '<script>' +
                            '$(function (){' +
                            'layui.use("upload", function () {' +
                            '            var upload = layui.upload;' +
                            '            upload.render({' +
                            '                elem: "#' + item.name + 'Upload",' +
                            '                url: "/jzApi/utils/fileImprot",' +
                            '                size: 1000,' +
                            '                accept: "file",' +
                            '                done: function (r) {' +
                            '                    $("#' + item.name + '").val(r.data);' +
                            '                    $("#' + item.name + 'Test").html(subFileName(r.data));' +
                            '                },' +
                            '                error: function (r) {' +
                            '                    layer.msg(r.msg);' +
                            '                }' +
                            '            });' +
                            '        });' +
                            '})';
                        $('#info').append(sc);

                    } else if (item.type == 5) {
                        info += '            <div class="div_3">' +
                            '                <label class="span_1">' + item.name + '下载：</label>' +
                            '                <label style="height: 50px;float: left;margin: 20px 10px auto auto;font-size: 16px;line-height: 50px;">' +
                            '                    <a target="_blank" style="color: blue" download href="' + item.content + '">' + item.name + '</a>' +
                            '                </label>' +
                            '            </div>';
                    }

                })
            }else {
                res.infoModelList.forEach(function (item, index) {
                    var len = item.name.length;
                    //alert();
                    var c="span_1";
                    if(len>25)c="span_2";
                    if (item.type == 0) {
                        info += "<div class='line'>" + item.name + "</div>";
                    } else if (item.type == 1) {
                        info += "            <div class='div_3'>" +
                            "                <label class='"+c+"'>" + item.name + "<span style='color: #D52525'>*</span>：</label>" +
                            "                <div id='adre'>" +
                            "<input type='text' name='" + item.name + "'  id='" + item.name + "' placeholder='请输入" + item.name + "' class='form-control inp_1'/>" +
                            "                </div>" +
                            "            </div>"
                    } else if (item.type == 2) {
                        info += '                <div class="div_3">' +
                            '                    <label class="'+c+'">' + item.name + '<span style="color: #D52525">*</span>：</label>' +
                            '                    <textarea  id="' + item.name + '" placeholder="' + item.explain + '"  class="form-control inp_2 ' + item.name + '"></textarea>' +
                            '                </div>';
                    } else if (item.type == 3) {
                        info += '                    <div class="div_3">' +
                            '                        <label class="'+c+'">' + item.name + '<span style="color: #D52525">*</span>：</label>' +
                            '                        <select class="form-control inp_1 ' + item.name + '" id="' + item.name + '">' +
                            '                            <option value="">--请选择--</option>';
                        var selectList = item.content.split(";;");
                        for (var i = 0; i < selectList.length; i++) {
                            info += '<option value="' + selectList[i] + '">' + selectList[i] + '</option>';
                        }
                        info += '                        </select>' +
                            '                    </div>';
                    } else if (item.type == 4) {
                        info += '<div class="div_3">' +
                            '                	 <label class="'+c+'">' + item.name + '<span style="color: #D52525">*</span>：</label>' +
                            '                		 <button type="button" class="btn inp_1" style="margin-top: 20px" id="' + item.name + 'Upload">' +
                            '                    		 <i class="fa fa-cloud"></i>请上传' + item.name +
                            '               	 	 </button>' +
                            '                	 <input type="text" style="opacity:0;width: 1px;" value="" class="' + item.name + '" id="' + item.name + '" name="' + item.name + '"/>' +
                            '                	 <span id="' + item.name + 'Test"></span>' +
                            '            	 </div>';
                        sc = '<script>' +
                            '$(function (){' +
                            'layui.use("upload", function () {' +
                            '            var upload = layui.upload;' +
                            '            upload.render({' +
                            '                elem: "#' + item.name + 'Upload",' +
                            '                url: "/jzApi/utils/fileImprot",' +
                            '                size: 1000,' +
                            '                accept: "file",' +
                            '                done: function (r) {' +
                            '                    $("#' + item.name + '").val(r.data);' +
                            '                    $("#' + item.name + 'Test").html(subFileName(r.data));' +
                            '                },' +
                            '                error: function (r) {' +
                            '                    layer.msg(r.msg);' +
                            '                }' +
                            '            });' +
                            '        });' +
                            '})';
                        $('#info').append(sc);

                    } else if (item.type == 5) {
                        info += '            <div class="div_3">' +
                            '                <label class="span_1">' + item.name + '下载：</label>' +
                            '                <label style="height: 50px;float: left;margin: 20px 10px auto auto;font-size: 16px;line-height: 50px;">' +
                            '                    <a target="_blank" style="color: blue" download href="' + item.content + '">' + item.name + '</a>' +
                            '                </label>' +
                            '            </div>';
                    }

                })
            }
            info+='            <div class="div_3">' +
                '                <button class="form-control but_1 send" onclick="submitFunction()" type="button">提交审核</button>' +
                '                <button class="form-control but_1" onclick="saveCao()" type="button">保存草稿</button>' +
                '            </div>';
            $('#info').html(info);
        });
    });

    function submitFunction(){
        var content="{";
        for(var i=0;i<infoModelList.length;i++){
            if(infoModelList[i].type==1 || infoModelList[i].type == 2 || infoModelList[i].type == 3 || infoModelList[i].type == 4){
                //alert($(document.getElementById(""id"")).val());
                if($(document.getElementById(infoModelList[i].name)).val()==""||$(document.getElementById(infoModelList[i].name)).val()==null){
                    layer.msg(infoModelList[i].name+"不能为空");
                    return false;
                }else{
                    content+='"'+infoModelList[i].name+'":"'+$(document.getElementById(infoModelList[i].name)).val()+'",';
                }
            }
            }
        content=content.substring(0,content.length-1);
        content+="}";
        ajaxToken("/jzApi/info/submitInfo", 'POST', {
            infoCollectId : infoCollectId,
            infoStoreId : infoStoreId,
            content : content
        },function (r){
            alert("提交成功，等待审核");
            window.reload();
        });

    }
    function saveCao() {
        var content="{";
        for(var i=0;i<infoModelList.length;i++){
            if(infoModelList[i].type==1 || infoModelList[i].type == 2 || infoModelList[i].type == 3 || infoModelList[i].type == 4){
                if($('#'+infoModelList[i].name).val()==""||$('#'+infoModelList[i].name).val()==null){
                    content+='"'+infoModelList[i].name+'":"",';
                }else{
                    content+='"'+infoModelList[i].name+'":"'+$('#'+infoModelList[i].name).val()+'",';
                }
            }
        }
        content+="}";
        ajaxToken1("/jzApi/info/saveInfo", 'POST', {
            infoCollectId : infoCollectId,
            infoStoreId : infoStoreId,
            content : content
        },function (r){
            if (r.code == 0) {
                layer.msg("自动保存成功", {offset: "rb"});
            } else {
                layer.confirm(r.msg);
                window.clearInterval(nz_bg)
            }
        });
    }
</script>
</html>